﻿using System.Globalization;
using System.IO;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MultipleDB.Entitys.DTO;

namespace RepositoryMultipleDataBases.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class DataFormatController : ControllerBase
    {
        [HttpGet("GetDataFormat/{Id}")]
        public IActionResult GetActionResult(int Id) 
        {
            return Ok(new { AId = Id, R = "Id123", DateTimes = DateTime.Now });
        }

        [HttpPost("GetSpecialSymbol/")]
        public IActionResult GetSpecialSymbol([FromBody] SpecialSymbolModel SymbolModel)
        {
            return Ok(new { SymbolModel });
        }
        /// <summary>
        /// 获取当前年份的周数
        /// </summary>
        /// <param name="Year">年份</param>
        /// <param name="Month">月份</param>
        /// <returns></returns>
        [HttpGet("GetAllWeekOfYear/")]
        public IActionResult GetAllWeekOfYear(int Year,int Month)
        {
            CultureInfo myCI = new CultureInfo("zh-CN");
            Calendar myCal = myCI.Calendar;
            CalendarWeekRule myCWR = myCI.DateTimeFormat.CalendarWeekRule;
            DayOfWeek myFirstDOW = myCI.DateTimeFormat.FirstDayOfWeek;
            var FirstDay = DateTime.Parse(Year.ToString() + "-01-01");
            int weekOfYear = myCal.GetWeekOfYear(FirstDay, myCWR, myFirstDOW);  //当年的第一天第1周

            DateTime LastDay = DateTime.Parse(Year.ToString() + "-12-31"); //因为每年最后一天都是31号

            var NowDay = DateTime.Parse(Year.ToString() + DateTime.Now.ToString("-MM-dd"));

            var NowWeekOfDay = myCal.GetWeekOfYear(NowDay, myCWR, myFirstDOW); //当天在一年中的第几周

            var AllWeek = myCal.GetWeekOfYear(LastDay, myCWR, myFirstDOW);  //一年的总周数

            var DaysInMonth = myCal.GetDaysInMonth(Year, Month);//这个月的在年份里面多少天

            var IsNowWeek = weekOfYear >= AllWeek ? "Yes" : "No";
            return Ok(new { NowWeek = weekOfYear, AllWeek, LastDay.Year, IsNowWeek, NowDay, NowWeekOfDay , DaysInMonth });
        }
    }
}
